package com.company.project.common.job.task;

import com.company.project.common.utils.Constant;
import com.google.common.collect.Lists;

import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.entity.EJkzGrdjxxEntity;
import com.company.project.entity.EJkzRecordLogEntity;
import com.company.project.entity.SysLog;
import com.company.project.service.BasicInformationTaskService;
import com.company.project.service.EJkzGrdjxxService;
import com.company.project.service.EJkzRecordLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.swing.text.html.parser.Entity;
import java.util.Collections;
import java.util.List;

/**
 * 基本信息上传任务
 *
 * @author liuhui
 * @Created 2020-11-13
 */
@Component("basicInformationTask")
@Slf4j
public class BasicInformationTask {

    private static final Logger logger = LoggerFactory.getLogger(BasicInformationTask.class);

    @Resource
    private EJkzGrdjxxService eJkzGrdjxxService;
    @Resource
    private BasicInformationTaskService basicInformationTaskService;

    public void run(String params) {
        log.info("健康证信息-基本信息上传,参数：{}", params);
        int successNum = 0;
        LambdaQueryWrapper<EJkzGrdjxxEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EJkzGrdjxxEntity::getUploadStatus, Constant.DATA_UPLOAD_NOT_UPLOAD);
        List<EJkzGrdjxxEntity> list = eJkzGrdjxxService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        for (EJkzGrdjxxEntity item : list) {
            boolean uploadResult = basicInformationTaskService.uploadBasicInformation(item);
            if (uploadResult) {
                successNum++;
            }
        }
        log.info("健康证信息-基本信息上传,待上传数：{} ,成功上传{}", list.size(), successNum);
    }
}
